﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace Kiosk
{
    /// <summary>
    /// Interaction logic for ContactMentor.xaml
    /// </summary>
    public partial class ContactMentor : Window
    {

        public string emailText { get; set; }
        public ContactMentor()
        {
            InitializeComponent();
            displayEmailText();
        }//end constructor ContactMentor

        /// <summary>
        /// This method queries the database for the student email template and the mentor name being emailed
        /// and sets the email text box to the email template and the label to "Contact [Insert Mentor Name]"
        /// </summary>
        private void displayEmailText()
        {
            try
            {
                string sqlQuery2 = "SELECT CONCAT_WS(' ', first_name, last_name) AS fullname FROM mentor WHERE mentor_id = '" + sGlobals.selectedMentorID + "'";
                string mentorName = sGlobals.dbWrapper.ExecuteScalarSQL(sqlQuery2);
                lblContact.Content = "Contact " + mentorName;
                string emailQuery = "SELECT email FROM users WHERE username = '" + sGlobals.currentUsername + "'";
                string sqlQuery = "SELECT email_text FROM email_template WHERE template_type = 'STUDENT'";
                emailText = mentorName + ",\r\n\n" + sGlobals.dbWrapper.ExecuteScalarSQL(sqlQuery) + "\r\n\nContact me at " + sGlobals.dbWrapper.ExecuteScalarSQL(emailQuery) + "\r\n\n";
                txtBoxEmail.Text = emailText;
            }
            catch (Exception ex)
            {
                if (!sGlobals.hasLogout)
                {
                    WarningMessage warning = new WarningMessage();
                    warning.lblMessage.Content = "There was a problem loading the page.\r\nIf the problem persists please contact your system administrator";
                    warning.ShowDialog();
                }
            }
        }

        /// <summary>
        /// This method returns the user to the previous page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            sGlobals.mentorDisplay.Show();
            this.Hide();
        }//end method btnBack_Click

        /// <summary>
        /// This method logs the user out of the kiosk. It is called when the user presses the logout button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogout_Click(object sender, RoutedEventArgs e)
        {
            sGlobals.logout();
        }//end method btnLogout_Click

        /// <summary>
        /// This method takes the user to the AdditionalComments page when the button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddComments_Click(object sender, RoutedEventArgs e)
        {
            AdditionalComments comments = new AdditionalComments();
            comments.Tag = "comments";
            comments.Show();
            this.Hide();
        }//end method btnAddComments_Click

        /// <summary>
        /// This method brings up window to prompt user for password.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSendEmail_Click(object sender, RoutedEventArgs e)
        {
            PasswordPrompt passPrompt = new PasswordPrompt();
            passPrompt.previousWindow = sGlobals.contactMentor;
            passPrompt.Show();
            this.Hide();
        }

        private void btnPathways_Click(object sender, RoutedEventArgs e)
        {
            sGlobals.pathways.Show();
            this.Hide();
        }

        private void btnFocusedAreas_Click(object sender, RoutedEventArgs e)
        {
            sGlobals.focusedAreasOfStudy.Show();
            this.Hide();
        }

        private void Window_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            displayEmailText();
        }
    }//end partial class ContactMentor : Window
}//end namespace Kiosk
